MSGMUSIC.DLL DLL to replace the MessageBeep and MessageBox statments in the Windows API. by Jonathan Zuck Published in the Windows Tech Journal May '92 Under Windows 3.1 we have seen that the wType parameter of the MessageBeep statment is to play a particular .WAV file and that these same constants correspond to the ones used to put icons in message boxes. For those without Windows 3.1, or without Sound cards, I have written these functions to provide similar functionality. Function Summaries: MusicBeep Same as MessageBeep but plays a sound MusicBox Same as MessageBox but plays a sound Function Declarations: Declare Sub MusicBeep Lib "msgmusic.dll" (ByVal wType) Declare Function MusicBox Lib "msgmusic.dll" (ByVal hWnd, ByVal Text$, ByVal Caption$, ByVal wType) The wType parameter in both cases, corresponds to the values used with a MessageBox (MsgBox in VB). They are the following: Const MB_ICONSTOP = 16 ' Critical message Const MB_ICONQUESTION = 32 ' Warning query Const MB_ICONEXCLAMATION = 48 ' Warning message Const MB_ICONINFORMATION = 64 ' Information message which you "Or" with other constants to specify which buttons should be displayed in the message box and which button should be the default. The functions work in an identical fashion except that they produce a sound which roughly corresponds to the icon that appears in the message box. These are the constants the the sounds that they produce with these functions: MB_NOICON (&H0) Doorbell MB_ICONSTOP (&H10) Britsh 2-tone siren MB_ICONQUESTION (&H20) "Huh?!" MB_ICONEXCLAMATION (&H30) "Oh, oh!" MB_ICONINFORMATION (&H40) Phone Differences with VB: The BEEP statement in VB, actually calls the MessageBeep function in the Windows API and passes a 0 as the wType. You will need to use the declaration as above when calling MusicBeep instead. This can be useful if you want to associate these sounds with something other than a message box, perhaps your own VB form. I also use them a lot in debugging code. Please note that none of these constants actually produces the boring beep. You will have to call out to BEEP to accomplish that. The MessageBox statment in the Windows API has an additional parameter at the beginning which is the hWnd of the parent window that is to own the MessageBox. This can be set to the hWnd of the current form or even to zero. It is in this function to maintain compatibility with the MessageBox statment in the API. You could construct a function in VB which is similar to the MsgBox function in the following way: Function MusicMsgBox (Msg$, Type%, Title$) MusicMsgBox = MusicBox (Screen.ActiveForm.hWnd, Msg$, Title$, Type%) End Function Please note that none of these parameters are opptional as they are in VB. Source Code: The C source code for MSGMUSIC.DLL can be found in Lib 9 of CLMFORUM. For both source and explanation, you need to order a back issue of the Windows Tech Jouranal, May '92. For more information or subscriptions to the Windows Tech Journal, call (800) 234 - 0386 or outside of the US, (503) 747 - 0800. The fax number is (503) 747 - 0071. Alternatively, you may reach the editor, J.D. Hildebrand (until he becomes too popular) here on CIS at id: 76701,32. The journal can be reached by mail at: Windows Tech Journal P.O. Box 70167 Eugene, OR 97401-0110 Thanks a lot for your interest! -=- Jonathan